const DB = require('../../../utils/db')
const JwtUtil = require('../../../utils/jwt')
/**
 * GET,
 * 获取群成员申请列表
 * 申请添加我所创建的群聊
 */

module.exports = async (ctx) => {
  // 获取token
  let token = ctx.request.header.authorization
  let jwt = new JwtUtil(token)
  // 用token获取到userid
  let userid = jwt.verifyToken()
  // 从group表查我（761916205@qq.com）所创建的群，再根据这些群从user_group_apply中查询，有哪些人申请（需要的字段avatar,userid,username,applyStatus）
  const applyList = await DB.query(
    `SELECT uga.applyStatus, u.avatar, u.userid, u.username,uga.groupid from \`group\` g join user_group_apply uga on g.groupid = uga.groupid 
join user u on u.userid = uga.userid where lord = '${userid}'`
  )

  ctx.body = {
    code: 0,
    data: applyList,
  }
}
